package com.gitee.huanminabc.jcommon.exception;

public class StackTraceUtil {

    public static StackTraceElement stackTraceLevel(int num) {
        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
        if (stackTrace.length >= num+ 1) {
            return stackTrace[num];
        }
        return new StackTraceElement("null", "null", "null", 0);
    }

    //获取调用此方法的  类名.方法名(类名.java:行号)
    public static String stackTraceLocation(StackTraceElement stackTraceElement) {
       return stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + "(" + stackTraceElement.getFileName() + ":" + stackTraceElement.getLineNumber() + ")";
    }

}
